﻿using Serilog;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Text;

namespace CommonLib
{
    public class CommonLog
    {
        static CommonLog()
        {
            Log.Logger = new LoggerConfiguration()
                .WriteTo.Console()
                .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Debug).WriteTo.File("Logs\\Debug.log", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Information).WriteTo.File("Logs\\Information.log", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Warning).WriteTo.File("Logs\\Warning.log", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Error).WriteTo.File("Logs\\Error.log", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lg => lg.Filter.ByIncludingOnly(p => p.Level == LogEventLevel.Fatal).WriteTo.File("Logs\\Fatal.log", rollingInterval: RollingInterval.Day))
                .CreateLogger();
        }

        /// <summary>
        /// 创建一般log
        /// </summary>
        /// <param name="message"></param>
        public static void Info(Type objType, string message)
        {
            Log.Information(objType.Name + ":" + message);
        }
        public static void Info(string className, string message)
        {
            Log.Information(className + ":" + message);
        }
        /// <summary>
        /// 创建错误log
        /// </summary>
        /// <param name="message"></param>
        public static void Error(Type objType,string message)
        {
            Log.Error(objType.Name + ":" + message);
        }
        public static void Error(string className, string message)
        {
            Log.Error(className + ":" + message);
        }
        /// <summary>
        /// 创建debug的log
        /// </summary>
        /// <param name="message"></param>
        public static void Debug(Type objType, string message)
        {
            Log.Debug(objType.Name + ":" + message);
        }
        public static void Debug(string className, string message)
        {
            Log.Debug(className + ":" + message);
        }
    }
}
